package com.zhijian.warehouse.manage.controller.app;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.vo.request.CategorySearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.CategoryVo;
import com.zhijian.warehouse.manage.enums.DelFlagEnum;
import com.zhijian.warehouse.manage.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 品类 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-10 20:08:21
 */
@Slf4j
@Controller
@Api(tags = "app品类")
@RequestMapping("/app")
public class AppCategoryController {

    @Autowired
    private CategoryService service;

    /**
     * 查询所有品类树
     *
     * @return
     */
    @Response
    @PostMapping("/category/list/tree")
    @ApiOperation("查询所有品类树")
    public List<CategoryVo> selectListTree() {
        return service.selectAllToTree();
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/category/page")
    @ApiOperation("分页查询")
    public Page<CategoryVo> selectByCondition(@RequestBody(required = false) CategorySearchVo param) {
        if (param == null)
            param = CategorySearchVo.builder().build();
        param.setIsDelete(DelFlagEnum.USING.value);
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/category/list")
    @ApiOperation("列表查询")
    public List<CategoryVo> selectList(@RequestBody(required = false) CategorySearchVo param) {
        if (param == null)
            param = CategorySearchVo.builder().build();
        param.setIsDelete(DelFlagEnum.USING.value);
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }
}